package exam.web.action;

import java.util.Date;

import exam.common.util.NullCheckUtil;
import exam.model.entity.TUserEntity;
import exam.web.action.base.StudentActionBase;

public class AddStudentAction extends StudentActionBase {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	public String execute() throws Exception {
		String btAdd = request.getParameter("btAdd");
		if (NullCheckUtil.isNUll(btAdd)) {
			addActionMessage("Thêm thí sinh");
			return INPUT;
		} else {
			if (NullCheckUtil.isNotNull(
					studentDAO.selectByCd(tStudentEntity.getStudentCd()))) {
				addActionError("Mã sinh viên đã tồn tại");
				return ERROR;
			}
			tStudentEntity.setCreateDate(new Date());
			tStudentEntity.setUpdateDate(new Date());
			tStudentEntity.setUserEntity(
					new TUserEntity(tStudentEntity.getUserId()));
			studentDAO.insertStudent(tStudentEntity);
			addActionMessage("Thêm thí sinh thành công");
			return SUCCESS;
		}
	}

}
